package com.hfy.shop.mapper;

import com.hfy.model.po.good.CommonGoodPo;
import com.hfy.model.po.good.VipPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/9/9 11:29
 */

@Mapper
public interface GoodMapper {

    @Select("SELECT id, title, sale_price salePrice, origin_price originPrice, discount_type discountType, cover " +
            "FROM vip_goods WHERE vip_type = #{vipType}")
    List<VipPo> getAnyVips(@Param("vipType") Integer vipType);


    @Select("SELECT id, title, sale_price salePrice, origin_price originPrice, discount_type discountType, store, sales, cover, have_store haveStore, pay_type payType, is_put isPut " +
            "FROM common_goods WHERE is_put = #{isPut}")
    List<CommonGoodPo> getCommonGoods(@Param("isPut") Integer isPut);

    @Select("SELECT id, title, sale_price salePrice, origin_price originPrice, discount_type discountType, store, sales, cover, have_store haveStore, pay_type payType, is_put isPut " +
            "FROM common_goods WHERE id = #{goodId}")
    CommonGoodPo queryGoodById(@Param("goodId") Integer goodId);

    @Update("UPDATE `common_goods` SET `store` = store-1 WHERE id = #{id}")
    void lockStore(@Param("id") Integer id);

    @Update("UPDATE `common_goods` SET `store` = store+1 WHERE id = #{id}")
    void unLockStore(@Param("id") Integer id);

    @Update("UPDATE `common_goods` SET sales = sales + 1 WHERE id = #{goodId}")
    void increaseSales(@Param("goodId") Integer goodId);
}
